Persistent Homology and Noise

1D Examples

In [1]:
from helper_functions import sample_circle_disc
import numpy as np
In [2]:
from bokeh.io import output_notebook, show
output_notebook()
Loading BokehJS ...
In [3]:
from one_parameter_plotting import Rips_Filtration
/home/ollie/anaconda3/lib/python3.7/site-packages/sklearn/utils/__init__.py:4: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated, and in 3.8 it will stop working
  from collections import Sequence

Single Loop

In [4]:
points = sample_circle_disc(1,100)
show(Rips_Filtration(points,[0.01,2]))

Multiple Loops Different Sizes

Sample 100 points from a disc of radius 1 and a disc of radius 0.5.

In [5]:
points = np.vstack((sample_circle_disc(1,100, radius = 1, centre = [0,1]),
                    sample_circle_disc(1,100, radius = 0.5, centre = [0,-1])))

show(Rips_Filtration(points,[0.01,2]))

Adding Noise to 1D

Sample 80 points on the unit circle and 20 points from the unit disc. Observe the diminished length of the bars in the H_1 barcode

In [6]:
points = sample_circle_disc(0.8,100)
show(Rips_Filtration(points,[0.01,2]))

Adding Noise to 1D continued

If we sample a point cloud with noise from 2 different size circles we can no longer distinguish 2 significant bars.

In [7]:
points = np.vstack((sample_circle_disc(0.8,100, radius = 1, centre = [0,1]),
                    sample_circle_disc(0.8,100, radius = 0.5, centre = [0,-1])))

show(Rips_Filtration(points,[0.01,2]))

2D Persistence

Single Loop with Noise Revisited

Use multiparameter persistence to filter out noise in second variable. We shall filter our point cloud by the k-nearest neighbour function, so that the noise points are excluded when we examing the high density (low codensity) points.

In [8]:
from multiparameter_landscape_plotting import Rips_Codensity_Bifiltration
In [ ]:
 
In [19]:
points = sample_circle_disc(0.8,100)
show(Rips_Codensity_Bifiltration(points,[0,2], 
                                 kNN = 5,
                                 maxind=3, 
                                 dim = 1))

We can recover 2 features of different scales in the 1st landscape.

In [23]:
points = np.vstack((sample_circle_disc(0.8,100, radius = 1, centre = [0,1]),
                    sample_circle_disc(0.8,100, radius = 0.5, centre = [0,-1])))
show(Rips_Codensity_Bifiltration(points,[0,1.5],10,maxind=3, dim = 1))

If we have two features of the same size then we detect this in the 2nd landscape.

In [10]:
points = np.vstack((sample_circle_disc(0.8,100, radius = 0.5, centre = [-0.5,0]),
                    sample_circle_disc(0.8,100, radius = 0.5, centre = [0.5,0])))
show(Rips_Codensity_Bifiltration(points,[0,1],5,maxind=3, dim = 1))

Statistics

In [12]:
from multiparameter_landscape import multiparameter_landscape
from helper_functions import Compute_Rivet, kNN_filter
one_loop_points = [sample_circle_disc(0.8,100, radius = 0.5, centre = [-0.5,0]) for _ in range(10)]
two_loop_points = [np.vstack((sample_circle_disc(0.8,100, radius = 0.5, centre = [-0.5,0]),
                    sample_circle_disc(0.8,100, radius = 0.5, centre = [0.5,0]))) for _ in range(10)]

one_loop_rivet_files = [Compute_Rivet(kNN_filter(points, kNN = 5)) for points in one_loop_points]
two_loop_rivet_files = [Compute_Rivet(kNN_filter(points, kNN = 5)) for points in two_loop_points]

one_loop_landscapes = [multiparameter_landscape(rivet_file, bounds = [[0,0],[1,1]], grid_step_size= 0.02) for rivet_file in one_loop_rivet_files]
two_loop_landscapes = [multiparameter_landscape(rivet_file, bounds = [[0,0],[1,1]], grid_step_size= 0.02) for rivet_file in two_loop_rivet_files]
In [14]:
from multiparameter_landscape_plotting import compare_multiparameter_landscape_samples

show(compare_multiparameter_landscape_samples(Samples = [one_loop_landscapes, two_loop_landscapes], 
                                         indices = [1,3], 
                                         GroupLabels = ['One Loop', 'Two Loops']))
In [15]:
large_loop_points = [sample_circle_disc(0.8,100, radius = 0.5, centre = [-0.5,0]) for _ in range(10)]
small_loop_points = [sample_circle_disc(0.8,100, radius = 0.3, centre = [-0.5,0]) for _ in range(10)]

large_loop_rivet_files = [Compute_Rivet(kNN_filter(points, kNN = 5)) for points in large_loop_points]
small_loop_rivet_files = [Compute_Rivet(kNN_filter(points, kNN = 5)) for points in small_loop_points]

large_loop_landscapes = [multiparameter_landscape(rivet_file, bounds = [[0,0],[1,1]], grid_step_size= 0.02) for rivet_file in large_loop_rivet_files]
small_loop_landscapes = [multiparameter_landscape(rivet_file, bounds = [[0,0],[1,1]], grid_step_size= 0.02) for rivet_file in small_loop_rivet_files]
In [16]:
show(compare_multiparameter_landscape_samples(Samples = [large_loop_landscapes, small_loop_landscapes], 
                                         indices = [1,3], 
                                         GroupLabels = ['Large Loop', 'Small Loop']))